﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memento
{
    class Program
    {
        static void Main(string[] args)
        {
            //Originator o = new Originator();
            //o.State = "aa";

            ////Memento m = o.CreateMemento();
            //Caretaker c = new Caretaker();
            //c.Memento = o.CreateMemento();

            //o.State = "bb";
            //o.SetMemento(c.Memento);

            SalesProspect s = new SalesProspect();
            s.Name = "Noel van Halen";
            s.Phone = "(412) 256-0990";
            s.Budget = 25000.0;

            ProspectMemory p = new ProspectMemory();
            p.Memento = s.SaveMemento();

            // Continue changing originator
            s.Name = "Leo Welch";
            s.Phone = "(310) 209-7111";
            s.Budget = 1000000.0;

            s.RestoreMemento(p.Memento);

            Console.Read();
        }
    }

    //class Originator
    //{
    //    private string _state;

    //    public string State
    //    {
    //        get { return _state; }
    //        set
    //        {
    //            _state = value;
    //            Console.WriteLine("State="+_state);
    //        }
    //    }

    //    public Memento CreateMemento()
    //    { 
    //        return (new Memento(_state));
    //    }

    //    public void SetMemento(Memento memento)
    //    {
    //        Console.WriteLine("Restoring state...");
    //        State = memento.State;
    //    }
    //}

    //class Memento
    //{
    //    private string _state;

    //    public Memento(string state)
    //    {
    //        this._state = state;
    //    }

    //    public string State
    //    {
    //        get
    //        {
    //            return this._state;
    //        }
    //    }
    //}

    //class Caretaker
    //{
    //    private Memento _memento;

    //    public Memento Memento
    //    {
    //        get { return this._memento; }
    //        set { this._memento = value; }
    //    }
    //}

    class SalesProspect
    {
        private string _name;
        private string _phone;
        private double _budget;

        // Gets or sets name
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                Console.WriteLine("Name:  " + _name);
            }
        }

        // Gets or sets phone
        public string Phone
        {
            get { return _phone; }
            set
            {
                _phone = value;
                Console.WriteLine("Phone: " + _phone);
            }
        }

        // Gets or sets budget
        public double Budget
        {
            get { return _budget; }
            set
            {
                _budget = value;
                Console.WriteLine("Budget: " + _budget);
            }
        }

        public Memento SaveMemento()
        {
            return new Memento(_name,_phone,_budget);
        }

        public void RestoreMemento(Memento memento)
        {
            Console.WriteLine("\nRestoring state --\n");
            this.Name = memento.Name;
            this.Phone = memento.Phone;
            this.Budget = memento.Budget;
        }
    }

    class Memento
    {
        public Memento(string name, string phone, double budget)
        {
            this.Name = name;
            this.Phone = phone;
            this.Budget = budget;
        }
        public string Name{ get; set; }
        public string Phone { get; set; }
        public double Budget { get; set; }
    }

    class ProspectMemory
    {
        public Memento Memento { get; set; }
    }
}
